package com.twu.biblioteca;

import java.util.HashMap;

/**
 * Created by isabellali on 4/06/2014.
 * Class of Book Details and Book Checkout and Return
 */
public class Book {
    private String bookName;
    private String Author;
    private int yearPublished;
    private boolean inLibrary;

    Book(String bookName, String Author, int yearPublished){
        this.bookName = bookName;
        this.Author = Author;
        this.yearPublished = yearPublished;
        this.inLibrary = true;
    }
    Book(){
        this.bookName = null;
        this.Author = null;
        this.yearPublished = 0;
        this.inLibrary = true;
    }

    public String getBookName() {
        return bookName;
    }

    public void setBookName(String bookName) {
        this.bookName = bookName;
    }

    public int getYearPublished() {
        return yearPublished;
    }

    public void setYearPublished(int yearPublished) {
        this.yearPublished = yearPublished;
    }

    public String getAuthor() {
        return Author;
    }

    public void setAuthor(String author) {
        Author = author;
    }

    public boolean isInLibrary() {
        return inLibrary;
    }

    public void setInLibrary(boolean inLibrary) {
        this.inLibrary = inLibrary;
    }

    public String checkOutBook(Book book, HashMap<String,Book> bookLibrary){
        if(bookLibrary.containsKey(book.getBookName())) {
            Book temp = bookLibrary.get(book.getBookName());
            if(!temp.isInLibrary())
                return  "That book is not available.";
            else{
                temp.setInLibrary(false);
                bookLibrary.put(book.getBookName(),temp);
                return "Thank you! Enjoy the book.";
            }
        }
        return "That book is not available.";
    }

    public String returnBook(Book book, HashMap<String,Book> bookLibrary){
        if(bookLibrary.containsKey(book.getBookName())){
            Book temp = bookLibrary.get(book.getBookName());
            if(temp.isInLibrary())
                return "That is not a valid book to return.";
            else{
                temp.setInLibrary(true);
                bookLibrary.put(temp.getBookName(),temp);
                return "Thank you for returning the book.";
            }
        }
        return "That is not a valid book to return.";
    }
}
